#!/bin/sh

echo "start install mangjings"

if [ -n "$1" ]; then
   if [ "$1" == "-h" ]; then
		echo '  #./install.sh              --for cloud'
		echo '  #./install.sh 192.168.X.X  --for local'
		exit 0
   fi
fi

install_root=/etc/mangjings

if [ ! -d $install_root ]; then
	mkdir -p $install_root
else
	./package/mjs stop
	rm -rf $install_root/*
fi

cp -rf ./package/* $install_root
cp -f uninstall.sh $install_root
mkdir -p $install_root/logs

ln -snf $install_root/mjs /usr/bin/mjs

if [ -n "$1" ]; then
	sed -i 's/\"debug\": \"no\"/\"debug\": \"yes\"/g' $install_root/conf/mangjings.json
	sed -i 's/\"local\": \"0.0.0.0\",/\"local\": \"'$1'\",/g' $install_root/conf/mangjings.json
fi

cat ./package/version

mjs start

echo "install mangjings completely"
